package com.stx.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.stx.entity.Film;
import com.stx.service.FilmService;

/*
 * 用户首页的显示的到电影的list
 * */
public class GetFilmList extends ActionSupport {

	private List<Film> filmList=new ArrayList<Film>();
	private List<Film> randomFilmList=new ArrayList<Film>();
	private FilmService fs;
	private int  allPage;
	private int  offsetPage;
	
	
	public List<Film> getRandomFilmList() {
		return randomFilmList;
	}
	public void setRandomFilmList(List<Film> randomFilmList) {
		this.randomFilmList = randomFilmList;
	}
	public int getAllPage() {
		return allPage;
	}
	public void setAllPage(int allPage) {
		this.allPage = allPage;
	}
	public int getOffsetPage() {
		return offsetPage;
	}
	public void setOffsetPage(int offsetPage) {
		this.offsetPage = offsetPage;
	}
	
	
	public List<Film> getFilmList() {
		return filmList;
	}
	public void setFilmList(List<Film> filmList) {
		this.filmList = filmList;
	}
	public FilmService getFs() {
		return fs;
	}
	public void setFs(FilmService fs) {
		this.fs = fs;
	}
	
	/*
	 * 显示到主页的需要得到随机的3个film
	 *                   最新的3个film
	 *                   最新的影评
	 * */
	
	public String findSomeFilm(){
		filmList=fs.getFilmList();
		randomFilmList=fs.getRandomFilmList(3);
		for(int i=0;i<randomFilmList.size();i++){
			System.out.println("主页信息"+randomFilmList.get(i).getFi_actor());
		}
		return "success";
	}
	/*
	 * 影视列表的到一个分页每页显示4个
	 * 需要简单计算下总的条数 分页显示风格是什么样的
	 * 需要第一个查询点 offsetPage allPage
	 * 得到总的信息条数
	 * 第一次offsetPage=0;offst的默认的是0
	 * 显示的时候根据allPage判定是否要下一页
	 * 如果手动输入页码
	 * */
	public String findAllFilm(){
		int countPage=4;
		int count=fs.getCountFilmList();
		if(count%4==0){
			allPage=count/4;
		}else{
			 allPage=count/4+1;
		}
		//简单判断下是否认为输入页码
		if(offsetPage==allPage){
			offsetPage--;
		}else if(offsetPage>allPage-1){
			offsetPage=0;
		}
		filmList=fs.getSomeList(offsetPage*countPage,countPage);
		return "success";
	}
	
	public String findYitongFilm(){
		int countPage=4;
		int count=fs.getCountFilmList();
		if(count%4==0){
			allPage=count/4;
		}else{
			 allPage=count/4+1;
		}
		//简单判断下是否认为输入页码
		if(offsetPage==allPage){
			offsetPage--;
		}else if(offsetPage>allPage-1){
			offsetPage=0;
		}
		filmList=fs.getYitongFilmList(offsetPage*countPage,countPage);
		return "success";
	}
}
